package com.xiaoq.manager.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mongodb.morphia.Datastore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xiaoq.manager.entity.MerchantFunEntity;
import com.xiaoq.manager.repository.IMerchantFunRepository;

@Repository
public class MerchantFunRepositoryImpl implements IMerchantFunRepository {

	@Autowired
	private Datastore datastore;
	
	private static final Logger LOG = LoggerFactory.getLogger(MerchantFunRepositoryImpl.class);
	
	
	@Override
	public MerchantFunEntity findMerchantFunByCode(String code) {
		MerchantFunEntity merchantFun = datastore.find(MerchantFunEntity.class).field("code").equal(code).get();
		return merchantFun;
	}


	@Override
	public List<MerchantFunEntity> findMerchantFunList() {
		
		return datastore.find(MerchantFunEntity.class).asList();
	}


	@Override
	public Map<String, MerchantFunEntity> findMerchantFunMap() {
		Map<String, MerchantFunEntity> merchantFunMap = new HashMap<>();
		List<MerchantFunEntity>merchantFunList = datastore.find(MerchantFunEntity.class).asList();
		for(MerchantFunEntity merchantFun:merchantFunList){
			String code = merchantFun.getCode();
			merchantFunMap.put(code, merchantFun);
		}
		return merchantFunMap;
	}

	
}
